//
//  AboutAppViewController.m
//  FaceRecognition
//
//  Created by Sylar on 2016/12/7.
//  Copyright © 2016年 Sylar. All rights reserved.
//

#import "AboutAppViewController.h"
#import "WebViewController.h"
#import <CoreTelephony/CTCallCenter.h>
#import <CoreTelephony/CTCall.h>
@interface AboutAppViewController () <UIWebViewDelegate>
{
    
    UIButton *_callBtn;
}

@property (nonatomic, strong) CTCallCenter *callCenter;

@end

@implementation AboutAppViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view setBackgroundColor:colorFromHex(@"#F5F8FA")];
    
    self.navBar.nav_titleLabel.text = @"关于师云平安幼儿";
    
    [self setUpView];
    
    
    _callCenter = [[CTCallCenter alloc] init];
    _callCenter.callEventHandler = ^(CTCall* call) {
        if ([call.callState isEqualToString:CTCallStateDisconnected])
        {
            NSLog(@"挂断了电话咯Call has been disconnected");
        }
        else if ([call.callState isEqualToString:CTCallStateConnected])
        {
            NSLog(@"电话通了Call has just been connected");
        }
        else if([call.callState isEqualToString:CTCallStateIncoming])
        {
            NSLog(@"来电话了Call is incoming");
            
        }
        else if ([call.callState isEqualToString:CTCallStateDialing])
        {
            NSLog(@"正在播出电话call is dialing");
        }
        else
        {
            NSLog(@"嘛都没做Nothing is done");
        }
    };
    
}

- (void)setUpView {
    
    UIImageView *logo = [[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH/2 - 44.5 , SafeAreaTopHeight + 36, 89, 89)];
    [logo setImage:[UIImage imageNamed:@"120x120"]];
    
    [self.view addSubview:logo];
    
    UILabel *versionLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,149+SafeAreaTopHeight, SCREENWIDTH, 21)];
    [versionLabel setFont:[UIFont systemFontOfSize:17]];
    versionLabel.text = VERSIONCODE;
    versionLabel.textAlignment = NSTextAlignmentCenter;
    
    [self.view addSubview:versionLabel];
    
    UIButton *serviceBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    serviceBtn.tag = 12;
    [serviceBtn setFrame:CGRectMake(0, 206+SafeAreaTopHeight, SCREENWIDTH, 44)];
    [serviceBtn setTitle:@"服务协议" forState:(UIControlStateNormal)];
    [serviceBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [serviceBtn setBackgroundColor:[UIColor whiteColor]];
    [serviceBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [serviceBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
    serviceBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [serviceBtn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:serviceBtn];
    
    UIImageView *arrow1 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH - 23, 0, 8, 13)];
    arrow1.centerY = serviceBtn.centerY;
    [arrow1 setImage:[UIImage imageNamed:@"back_nor_"]];
    [self.view addSubview:arrow1];
    
    UIButton *privacyBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    privacyBtn.tag = 13;
    [privacyBtn setFrame:CGRectMake(0, 262+SafeAreaTopHeight, SCREENWIDTH, 44)];
    [privacyBtn setTitle:@"隐私政策" forState:(UIControlStateNormal)];
    [privacyBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [privacyBtn setBackgroundColor:[UIColor whiteColor]];
    [privacyBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [privacyBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
    privacyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [privacyBtn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:privacyBtn];
    
    UIImageView *arrow2 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH - 23, 0, 8, 13)];
    arrow2.centerY = privacyBtn.centerY;
    [arrow2 setImage:[UIImage imageNamed:@"back_nor_"]];
    [self.view addSubview:arrow2];
    
    /*
    UIButton *userBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    userBtn.tag = 14;
    [userBtn setFrame:CGRectMake(0, 322+64, SCREENWIDTH, 44)];
    [userBtn setTitle:@"使用说明" forState:(UIControlStateNormal)];
    [userBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [userBtn setBackgroundColor:[UIColor whiteColor]];
    [userBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [userBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
    userBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [userBtn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:userBtn];
    
    UIImageView *arrow3 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH - 23, 0, 8, 13)];
    arrow3.centerY = userBtn.centerY;
    [arrow3 setImage:[UIImage imageNamed:@"back_nor_"]];
    [self.view addSubview:arrow3];
    */
    
    UIButton *callBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _callBtn = callBtn;
    callBtn.tag = 11;
    [callBtn setFrame:CGRectMake(0, SCREENHEIGH - 100, SCREENWIDTH, 30)];
    [callBtn setTitle:@"客服热线:400-667-8009" forState:(UIControlStateNormal)];
    [callBtn setTitleColor:DEFAULTCOLOR forState:(UIControlStateNormal)];
    [callBtn addTarget:self action:@selector(callAction) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:callBtn];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Action

- (void)btnAction:(UIButton *)sender {
    
    WebViewController * webView = [[WebViewController alloc]init];
    if (sender.tag == 12) {
        webView.controllerTitle = @"服务协议";
        webView.requestURL = @"http://apichild.our100.net/about/yesysm/fwxy.html";
    }else if (sender.tag == 13){
        webView.controllerTitle = @"隐私政策";
        webView.requestURL = @"http://apichild.our100.net/about/yesysm/yszc.html";
    }else if (sender.tag == 14){
        webView.controllerTitle = @"使用说明";
        webView.requestURL = @"http://apichild.our100.net/about/payesysm/sysm.html";
    }
    [self.navigationController pushViewController:webView animated:YES];
}

- (void)callAction {
    
    NSString *phoneNum=@"400-667-8009";
    
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        [[UIApplication sharedApplication] openURL:phoneURL];
    });
    
    
}



@end
